<?php
/**
 * Ganglib
 *
 * LICENSE
 *
 * This source file is subject to the GNU Lesser Generak Public license.
 * 
 * It is available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/lgpl.html
 *
 * @category    Ganglib
 * @package    Div_Db_Query_Dialect
 * @copyright  Copyright (c) 2008 Ganglib project members (http://www.code.google.com/p/ganglib)
 * @license     http://www.gnu.org/licenses/lgpl.html
 */
 
 
/**
 * Interface for query dialects.
 * 
 * Query dialects are used for transform object-based query to
 * SQL string that could be performed on specified RDBMS.
 * 
 * @package    Div_Db_Query_Dialect
 * @copyright  Copyright (c) 2008 Ganglib project members (http://www.code.google.com/p/ganglib)
 * @license     http://www.gnu.org/licenses/lgpl.html
 */
interface Div_Db_Query_Dialect_Interface
{
	/**
	 * Return singleton instance
	 */
	public static function getInstance();
	
	/**
	 * Escape sql table column name to use in SQL Query
	 * 
	 * @param string $column column name
	 * @return escaped column name
	 */
	public function escape_column($column);
	
	/**
	 * Escape table name to use in SQL Query
	 * 
	 * @param string $table table name
	 * @return escaped table name 
	 */
	public function escape_table($table);

	/**
	 * Return REGEXP fragment - for DBMS specified dialect 
	 */
	public function regex($field, $match = '', $type = 'AND ', $num_regexs);

	/**
	 * Return NOT REGEXP fragment - for RDBMS specified dialect
	 */
	public function notregex($field, $match = '', $type = 'AND ', $num_regexs);


	public function merge($table, $keys, $values);

	/**
	 * Limit records in sql query
	 * 
	 * @param int $limit how many records
	 * @param int $offset starting record number
	 */
	public function limit($limit, $offset = 0);

	/**
	 * Escape string value in database-specific manner
	 * 
	 * @param string $str value to escape
	 * @return string escaped value
	 */
	public function escape_str($str);
	
		/**
	 * Builds a WHERE portion of a query.
	 *
	 * @param  mixed  $key
	 * @param  string $value
	 * @param  string $type
	 * @param  int    $num_wheres
	 * @param  bool   $quote
	 * @return string
	 */
	public function where($key, $value, $type, $num_wheres, $quote);

	/**
	 * Builds a LIKE portion of a query.
	 *
	 * @param  mixed  $field
	 * @param  string $match
	 * @param  string $type
	 * @param  int    $num_likes
	 * @return string
	 */
	public function like($field, $match = '', $type = 'AND ', $num_likes);
	
	/**
	 * Builds a IN() part of query
	 * 
	 * @param string $field name
	 * @param mixed $values
	 * @param string type AND or OR
	 */
	public function in($field, $values, $type= 'AND', $num_where);

	/**
	 * Builds a NOT IN() part of query
	 * 
	 * @param string $field name
	 * @param mixed $values
	 * @param string type AND or OR
	 */
	public function notin($field,  $values, $type= 'AND', $num_where);


	/**
	 * Builds a NOT LIKE portion of a query.
	 *
	 * @param  mixed  $field
	 * @param  string $match
	 * @param  string $type
	 * @param  int    $num_likes
	 * @return string
	 */
	public function notlike($field, $match = '', $type = 'AND ', $num_likes);

	/**
	 * Determines if the string has an arithmetic operator in it.
	 *
	 * @param  string $str
	 * @return boolean
	 */
	public function has_operator($str);

	/**
	 * Escapes any input value
	 *
	 * @param  mixed $value
	 * @return string
	 */
	public function escape($value, $quote = true);

	/**
	 * Compile SELECT query from specified data and return query string
	 * 
	 * @param array $parts query parts returned from Div_Db_Query_Dialect::asArray
	 */
	public function compile_select($parts);

	/**
	 * Compile UPDATE query from specified data and return query string
	 * 
	 * @param array $parts query parts returned from Rapid_Driver_Mysql::asArray
	 */	
	public function compile_update($parts);

	/**
	 * Compile DELETE query from specified data and return query string
	 * 
	 * @param array $parts query parts returned from Rapid_Driver_Mysql::asArray
	 */	
	public function compile_delete($parts);

	/**
	 * Compile INSERT query from specified data and return query string
	 * 
	 * @param array $parts query parts returned from Rapid_Driver_Mysql::asArray
	 */		

	public function compile_insert($parts);
	
}
?>
